home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 32 / Amiga Format AFCD32 (Nov 1998, Issue 117).iso / -seriously_amiga- / programming / c / mesa-2.6 / examples / speedtest / cybergl / triangles.c < prev   
C/C++ Source or Header  |  1998-08-10  |  4KB  |  161 lines

  1. /*
  2. **    $VER: triangles.c 1.0 (20.03.1997)
  3. **
  4. **    This is an example program for CyberGL
  5. **
  6. **      Written by Frank Gerberding
  7. **
  8. **    Copyright © 1996-1997 by phase5 digital products
  9. **      All Rights reserved.
  10. **
  11. */
  12.  
  13. /*
  14.  * triangles.c
  15.  *
  16.  * Modified  27 Jun 1998
  17.  * by Jarno van der Linden
  18.  * jarno@kcbbs.gen.nz
  19.  *
  20.  * Some changes to output some stats for comparison with AmigaMesaRTL
  21.  *
  22.  */
  23.  
  24.  
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <math.h>
  28. #include <time.h>
  29.  
  30. #include <clib/exec_protos.h>
  31. #include <proto/graphics.h>
  32. #include <proto/intuition.h>
  33.  
  34. #define CYBERGLNAME             "cybergl.library"
  35. #define CYBERGLVERSION          39L
  36.  
  37.  
  38. #define SHARED                  /* we use the cyberglshared library */
  39. #define GL_APICOMPATIBLE        /* we use stubs from cybergl.lib */
  40.  
  41.  
  42. #include <libraries/cybergl.h>
  43. #include <libraries/cybergl_display.h>
  44. #include <proto/cybergl.h>
  45.  
  46. #ifdef SHARED
  47. LONG __oslibversion   = 39L;
  48. LONG __CGLlibversion = CYBERGLVERSION;
  49. #endif
  50.  
  51.  
  52. #define WIDTH    300
  53. #define HEIGHT   200
  54.  
  55.  
  56.  
  57.  
  58.  
  59. void handle_window_events (struct Window *window)
  60. {
  61.   struct IntuiMessage *msg;
  62.   int                  done = 0;
  63.  
  64.   while (!done)
  65.   {
  66.     Wait (1L << window->UserPort->mp_SigBit);
  67.     while ((!done) && (msg = (struct IntuiMessage *) GetMsg (window->UserPort)))
  68.     {
  69.       switch (msg->Class)
  70.       {
  71.         case IDCMP_CLOSEWINDOW:
  72.           done = 1;
  73.           break;
  74.       }
  75.       ReplyMsg ((struct Message *) msg);
  76.     }
  77.   }
  78. }
  79.  
  80.  
  81.  
  82.  
  83.  
  84. void drawTriangles (int num)
  85. {
  86.   int count;
  87.   time_t t1,t2;
  88.  
  89.   glMatrixMode   (GL_PROJECTION);
  90.   glLoadIdentity ();
  91.  
  92. #ifndef GL_APICOMPATIBLE
  93.   {
  94.    GLortho glortho;
  95.  
  96.    glortho.left    = -400.0;
  97.    glortho.right   = 400.0;
  98.    glortho.bottom  = -300.0;
  99.    glortho.top     = 300.0;
  100.    glortho.zNear   = 500.0;
  101.    glortho.zFar    = -500.0;
  102.    glOrtho (&glortho);
  103.   }
  104. #else
  105.   glOrtho        (-400.0, 400.0, -300.0, 300.0, 500.0, -500.0);
  106. #endif
  107.   srand (42);
  108.  
  109.   t1 = time(NULL);
  110.   for (count = 0; count < num; count++)
  111.   {
  112.     glBegin (GL_TRIANGLES);
  113.       glColor3ub (rand () % 256, rand () % 256, rand () % 256);
  114.       glVertex3i (rand () % 800 - 400, rand () % 600 - 300, rand () % 1000 - 500);
  115.       glColor3ub (rand () % 256, rand () % 256, rand () % 256);
  116.       glVertex3i (rand () % 800 - 400, rand () % 600 - 300, rand () % 1000 - 500);
  117.       glColor3ub (rand () % 256, rand () % 256, rand () % 256);
  118.       glVertex3i (rand () % 800 - 400, rand () % 600 - 300, rand () % 1000 - 500);
  119.     glEnd ();
  120.   }
  121.   glFlush();
  122.  
  123.   t2 = time(NULL);
  124.   printf("Time = %d\n%d triangles per second\n",t2-t1,t2 != t1 ? num/(t2-t1) : num);
  125. }
  126.  
  127.  
  128.  
  129.  
  130.  
  131. void main (int argc, char *argv[])
  132. {
  133.   void     *window;
  134.   struct Screen *screen;
  135.  
  136.   screen = LockPubScreen("Mesa");
  137.   window  = openGLWindowTags (WIDTH, HEIGHT, GLWA_Title, "Triangles",
  138.                                              GLWA_PubScreen, screen,
  139.                                              GLWA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY,
  140.                                              GLWA_CloseGadget, TRUE,
  141.                                              GLWA_DepthGadget, TRUE,
  142.                                              GLWA_DragBar,     TRUE,
  143.                                              GLWA_Activate, TRUE,
  144.                                              GLWA_RGBAMode, GL_TRUE,
  145.                                              TAG_DONE);
  146.   UnlockPubScreen(NULL,screen);
  147.   if (window)
  148.   {
  149.     glEnable         (GL_DEPTH_TEST);
  150.     glEnable         (GL_DITHER);
  151.     glShadeModel     (GL_SMOOTH);
  152.     glClear          (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  153.  
  154.     drawTriangles    (argc == 2 ? atoi(argv[1]) : 500);
  155.  
  156.     handle_window_events (getWindow (window));
  157.  
  158.     closeGLWindow (window);
  159.   }
  160. }
  161.